public class Test18 {

    static int N;
    static int[] nums = {1, 2, 3};

    public static void permit() {
        //初始化
        N = nums.length;
        dfs(0);
    }

    //交换
    public static void swap(int[] nums, int i, int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }

    public static void output() {
        for (int i = 0; i < N; i++) {
            System.out.print(nums[i] + " ");
        }
        System.out.println();
    }

    public static void dfs(int row) {
        if (row == N) {
            output();
        } else {
            for (int i = row; i < N; i++) {
                swap(nums, i, row);
                dfs(row + 1);
                swap(nums, i, row);
            }
        }
    }

    public static void main(String[] args) {
        permit();
    }
}
